package com.gant.view;

import javafx.scene.control.*;
import javafx.scene.layout.*;

public class MainView {
    private BorderPane root;
    private TreeView<String> jsonTreeView;
    private TextField searchField;
    private Label totalItemsLabel;
    private Label loadTimeLabel;
    private Label pageInfoLabel;
    private Button prevPageButton;
    private Button nextPageButton;
    private TextField pageSizeField;
    private TextField gotoPageField;
    private Button gotoPageButton;
    private Button backButton;
    private Button openButton;
    private Button searchButton;

    public MainView() {
        initializeUI();
    }

    private void initializeUI() {
        // 组件初始化
        openButton = new Button("Open File");
        searchButton = new Button("Search");
        searchField = new TextField();
        searchField.setPromptText("Enter keyword...");
        totalItemsLabel = new Label("Total Items: 0");
        loadTimeLabel = new Label("Load Time: 0 ms");

        // 顶部工具栏
        HBox topBar = new HBox(10);
        Region spacer = new Region();
        HBox.setHgrow(spacer, Priority.ALWAYS);
        topBar.getChildren().addAll(openButton, spacer, new Label("Search:"), searchField, searchButton, totalItemsLabel, loadTimeLabel);
        topBar.setStyle("-fx-padding: 10; -fx-background-color: #ffffff;");

        // 树形视图
        jsonTreeView = new TreeView<>();
        jsonTreeView.setStyle("-fx-border-color: #cccccc; -fx-border-radius: 5;");
        jsonTreeView.setEditable(false);

        // 底部栏
        prevPageButton = new Button("◀");
        nextPageButton = new Button("▶");
        pageSizeField = new TextField("100");
        pageSizeField.setPrefWidth(60);
        gotoPageField = new TextField("1");
        gotoPageField.setPrefWidth(60);
        gotoPageButton = new Button("Go");
        pageInfoLabel = new Label("Page: 1/1");
        backButton = new Button("Back");

        HBox bottomBar = new HBox(10,
                backButton,
                new Label("Page Size:"), pageSizeField,
                prevPageButton, pageInfoLabel, nextPageButton,
                new Label("Go to Page:"), gotoPageField, gotoPageButton
        );

        // 根布局
        root = new BorderPane();
        root.setTop(topBar);
        root.setCenter(jsonTreeView);
        root.setBottom(bottomBar);
    }

    // Getter方法
    public BorderPane getRoot() { return root; }
    public TreeView<String> getJsonTreeView() { return jsonTreeView; }
    public TextField getSearchField() { return searchField; }
    public Label getTotalItemsLabel() { return totalItemsLabel; }
    public Label getLoadTimeLabel() { return loadTimeLabel; }
    public Label getPageInfoLabel() { return pageInfoLabel; }
    public Button getPrevPageButton() { return prevPageButton; }
    public Button getNextPageButton() { return nextPageButton; }
    public TextField getPageSizeField() { return pageSizeField; }
    public TextField getGotoPageField() { return gotoPageField; }
    public Button getGotoPageButton() { return gotoPageButton; }
    public Button getBackButton() { return backButton; }
    public Button getOpenButton() { return openButton; }
    public Button getSearchButton() { return searchButton; }
}